package com.ruoyi.web.controller.module.event;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.event.EventCleanAreaListInfo;
import com.ruoyi.system.service.module.event.IEventCleanAreaListInfoService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.web.controller.common.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 保洁区域与路线绑定Controller
 *
 * @author ruoyi
 * @date 2024-09-24
 */
@Validated
@Api(value = "保洁区域与路线绑定控制器", tags = {"保洁区域与路线绑定管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/areaInfo")
public class EventCleanAreaListInfoController extends BaseController {

    private final IEventCleanAreaListInfoService eventCleanAreaListInfoService;

    /**
     * 查询保洁区域与路线绑定列表
     */
    @ApiOperation("查询保洁区域与路线绑定列表")
    @PreAuthorize("@ss.hasPermi('module:areaInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<EventCleanAreaListInfo> list(@Validated EventCleanAreaListInfo eventCleanAreaListInfo) {
        QueryWrapper<EventCleanAreaListInfo> qw = new QueryWrapper<>();

        TableDataInfo<EventCleanAreaListInfo> td = PageUtils.buildDataInfo(eventCleanAreaListInfoService.page(PageUtils.buildPage(),qw));
        List<EventCleanAreaListInfo> list = td.getRows();
        return td;
    }

    /**
     * 导出保洁区域与路线绑定列表
     */
    @ApiOperation("导出保洁区域与路线绑定列表")
    @PreAuthorize("@ss.hasPermi('module:areaInfo:export')")
    @Log(title = "保洁区域与路线绑定", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EventCleanAreaListInfo> export(@Validated EventCleanAreaListInfo eventCleanAreaListInfo) {
        List<EventCleanAreaListInfo> list = eventCleanAreaListInfoService.list();
        ExcelUtil<EventCleanAreaListInfo> util = new ExcelUtil<EventCleanAreaListInfo>(EventCleanAreaListInfo.class);
        return util.exportExcel(list, "保洁区域与路线绑定");
    }

    /**
     * 获取保洁区域与路线绑定详细信息
     */
    @ApiOperation("获取保洁区域与路线绑定详细信息")
    @PreAuthorize("@ss.hasPermi('module:areaInfo:query')")
    @GetMapping("/{id}")
    public AjaxResult<EventCleanAreaListInfo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        EventCleanAreaListInfo eventCleanAreaListInfo = eventCleanAreaListInfoService.getById(id);
        return AjaxResult.success(eventCleanAreaListInfo);
    }

    /**
     * 新增保洁区域与路线绑定
     */
    @ApiOperation("新增保洁区域与路线绑定")
    @PreAuthorize("@ss.hasPermi('module:areaInfo:add')")
    @Log(title = "保洁区域与路线绑定", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody EventCleanAreaListInfo eventCleanAreaListInfo) {
        return toAjax(eventCleanAreaListInfoService.save(eventCleanAreaListInfo) ? 1 : 0);
    }

    /**
     * 修改保洁区域与路线绑定
     */
    @ApiOperation("修改保洁区域与路线绑定")
    @PreAuthorize("@ss.hasPermi('module:areaInfo:edit')")
    @Log(title = "保洁区域与路线绑定", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody EventCleanAreaListInfo eventCleanAreaListInfo) {
        return toAjax(eventCleanAreaListInfoService.updateById(eventCleanAreaListInfo) ? 1 : 0);
    }

    /**
     * 删除保洁区域与路线绑定
     */
    @ApiOperation("删除保洁区域与路线绑定")
    @PreAuthorize("@ss.hasPermi('module:areaInfo:remove')")
    @Log(title = "保洁区域与路线绑定" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(eventCleanAreaListInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
